﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using RuleCode.Table;

namespace map.member
{
    public partial class configshop_itemlist : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GridViewDataBind();
            }
        }



        private void GridViewDataBind()
        {
            cbuser u = cbuser.getcuruser();
            string id = u.cbuserid.ToString();
            cbshopcss sc = cbshopcss.findorcreate(id);
            string css = sc.getstylestring();
            Literalcss.Text = css;


            string cataid = "";
            if (this.Request.Params["kid"] != null)
            {
                cataid = this.Request.Params["kid"].ToString();
            }
            if (cataid=="")
            {
                if (this.Request.Params["itemcataid"] != null)
                {
                    cataid = this.Request.Params["itemcataid"].ToString();
                }
            }
            string sql;
            DataTable dt;
            //sql = "exec [dbo].[searchtextitem] '" + zfunction.ReplaceKeyWord("")
            //    + "' ,'" + "" + "' ,'" + zfunction.Province + "','"
            //    + "" + "' ,0,0,0,0,0,0,'" + cataid+"'";
            taobaoItemCat ic = taobaoItemCat.Find("taobaoparentcid ='"+cataid+"'");
            string cateFilter = string.Empty;
            for(int i=0;i<ic.Count ;i++)
            {
                cateFilter += " or taobaoseller_cids like '%"+ic.taobaocid.Value +"%' ";
                ic.Next();
            }
            string pcataid = ic.taobaoparentcid.ToString();
            string num = " ";
            if (this.Request.Params["filter"] != null)
            {
                num = " top 100 ";
            }
                       
            sql = " select "+num+" * from Vitem where taobaouserid = '" + id + "'" ;
            if (this.Request.Params["itemcataid"] != null)
            {
                sql += " and ( taobaoseller_cids like '%" + cataid + "%'"
                    + cateFilter + " )";
            }
            if (this.Request.Params["filter"] != null)
            {
                if (this.Request.Params["filter"].ToString() == "jptj")
                {
                    sql += " and taobaohas_showcase = 'true' ";
                }
                if (this.Request.Params["filter"].ToString() == "zxsp")
                {
                    sql += " order by taobaolist_time desc ";
                }
            }
            dt = RuleCode.Common.SqlHelper.Instance.ExecuteQuery(sql).Tables[0];
            WebPager1.DataSource = dt;
            WebPager1.DataBind();
            WebPager2.DataSource = dt;
            WebPager2.DataBind();
        }

        protected void WebPager1_PageIndexChanged(object sender, RuleCode.Controls.PageChangedEventArgs e)
        {
            GridViewDataBind();
            WebPager1.CurrentPageIndex= e.NewPageIndex;
        }
        protected void WebPager2_PageIndexChanged(object sender, RuleCode.Controls.PageChangedEventArgs e)
        {
            GridViewDataBind();
            WebPager2.CurrentPageIndex= e.NewPageIndex;
        }
    }
}
